package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.OperateDeviceManageGetPageDTO;
import com.itlong.cloud.POJO.PO.DeviceRunLogPO;
import com.itlong.cloud.POJO.PO.OperateUserInfoPO;
import com.itlong.cloud.POJO.PO.OperationSpecialLogPO;
import com.itlong.cloud.POJO.VO.operate.OperateDeviceDetailsVO;
import com.itlong.cloud.POJO.VO.operate.OperateDeviceManageInfoAllVO;
import com.itlong.cloud.POJO.VO.operate.OperatePassPercentVO;
import com.itlong.cloud.equip.operate.IOperateDeviceManageServiceClient;
import com.itlong.cloud.operate.service.IDeviceRunLogService;
import com.itlong.cloud.operate.service.IOperateDeviceManageService;
import com.itlong.cloud.utils.page.Page;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *     运营-项目管理-设备管理露接口实现类。
 * <desc/>
 *
 * @createDate 2019/01/18.
 */
@RestController
public class OperateDeviceManageServiceResource implements IOperateDeviceManageServiceClient {

    private static final Logger LOG = LoggerFactory.getLogger(OperateDeviceManageServiceResource.class);

    @Autowired
    IOperateDeviceManageService iOperateDeviceManageService;

    @Autowired
    IDeviceRunLogService iDeviceRunLogService;

    /**
     * <desc>
     *      分页获取设备信息。
     * <desc/>
     *
     * @param  dto 参数请求对象
     * @return
     * @author Qiang.S
     * @createDate 2019/01/18
     */
    @Override
    @RequestMapping(path = "/operate/project/deviceManage/getDeviceByPage",method = RequestMethod.POST)
    public OperateDeviceManageInfoAllVO getDeviceByPage(@RequestBody OperateDeviceManageGetPageDTO dto) throws Exception{
        return iOperateDeviceManageService.getDeviceByPage(dto);
     }


     /**
      * <desc>
      *     获取每个设备所占比例及统计在线与离线设备
      * </desc>
      *
      * @param
      * @return
      * @Author Zhu.yj
      * @createDate  2019/10/28
      */
    @Override
    @RequestMapping(path ="/operate/project/deviceManage/getOperateDeviceInfo",method = RequestMethod.POST)
    public OperateDeviceManageInfoAllVO getOperateDeviceInfo() throws Exception {
        return iOperateDeviceManageService.getOperateDeviceInfo();
    }

    /**
     * <desc>
     *      修改设备的状态 删除、恢复
     * </desc>
     *
     * @param dto 参数DTO
     * @return
     * @author Juguang.S
     * @createDate 2020/12/02
     */
    @Override
    @RequestMapping(path ="/operate/project/deviceManage/modifyDeviceStatus",method = RequestMethod.POST)
    public void modifyDeviceStatus(@RequestBody OperateDeviceManageGetPageDTO dto) throws Exception{
        iOperateDeviceManageService.modifyDeviceStatus(dto);
    }

    /**
     * <desc>
     *      根据设设备运行日志ID获取设备日志运行信息
     * </desc>
     *
     * @param runLogId 设备运行日志ID
     * @return DeviceRunLogPO
     * @author caoshuai
     * @createDate 2020/11/16 11:04
     */
    @Override
    @RequestMapping(path ="/operate/project/deviceManage/getDeviceRunLogInfo",method = RequestMethod.POST)
    public DeviceRunLogPO getDeviceRunLogInfo(@RequestParam("runLogId") String runLogId) {
        return iDeviceRunLogService.getDeviceRunLogInfo(runLogId);
    }

    /**
     * <desc>
     * 删除运行日志
     * </desc>
     *
     * @param runLogId 运行日志逻辑ID
     * @return Object
     * @author caoshuai
     * @createDate 2020/11/16 13:40
     */
    @Override
    @RequestMapping(path ="/operate/project/deviceManage/delRunLog",method = RequestMethod.POST)
    public Integer delRunLog(@RequestParam("runLogId") String runLogId) {
        return iOperateDeviceManageService.delRunLog(runLogId);
    }

    /**
     * <desc>
     * 运行日志列表
     * </desc>
     *
     * @param deviceUnique 设备ID
     * @return Object
     * @author caoshuai
     * @createDate 2020/11/16 13:40
     */
    @Override
    @RequestMapping(path ="/operate/project/deviceManage/getRunLogInfoPage",method = RequestMethod.POST)
    public Map<String, Object> getRunLogInfoPage(@RequestParam("deviceUnique") String deviceUnique, @RequestParam("pageSize") int pageSize,
                                                 @RequestParam("currentPage") int currentPage,  @RequestParam("orderRule") String orderRule) {
        return iOperateDeviceManageService.getRunLogInfoPage(deviceUnique, pageSize, currentPage, orderRule);
    }

    /**
     * <desc>
     * 设备重启业务
     * </desc>
     *
     * @param deviceUnique 设备ID
     * @return Object
     * @author caoshuai
     * @createDate 2020/11/16 13:40
     */
    @Override
    @RequestMapping(path ="/operate/project/deviceManage/restartDevice",method = RequestMethod.POST)
    public Integer restartDevice(@RequestParam("deviceUnique") String deviceUnique,
                                 @RequestParam(value = "deviceType", required = false) String deviceType) throws Exception {
        return iOperateDeviceManageService.restartDevice(deviceUnique, deviceType);
    }

    /**
     * <desc>
     * 获取设备业务
     * </desc>
     *
     * @param deviceUnique
     * @author caoshuai
     * @createDate 2020/11/25 15:34
     */
    @Override
    @RequestMapping(path ="/operate/project/deviceManage/getDeviceLog",method = RequestMethod.POST)
    public Integer getDeviceLog(@RequestParam("deviceUnique") String deviceUnique,
                                @RequestParam(value = "deviceId", required = false) String deviceId,
                                @RequestParam(value = "deviceType", required = false) String deviceType) throws Exception {
        return iOperateDeviceManageService.getDeviceLog(deviceUnique, deviceId, deviceType);
    }

    /**
     * <desc>
     * 获取详情
     * </desc>
     *
     * @param deviceUnique
     * @return
     * @author caoshuai
     * @createDate 2020/11/25 9:23
     */
    @Override
    @RequestMapping(path ="/operate/project/deviceManage/getDeviceDetails",method = RequestMethod.POST)
    public OperateDeviceDetailsVO getDeviceDetails(@RequestParam("deviceUnique") String deviceUnique) {
        return iOperateDeviceManageService.getDeviceDetails(deviceUnique);
    }

    /**
     * <desc>
     * 获取分页设备在线状态变更日志
     * </desc>
     *
     * @param deviceUnique
     * @param pageSize
     * @param currentPage
     * @return
     * @author caoshuai
     * @createDate 2020/11/25 9:23
     */
    @Override
    @RequestMapping(path ="/operate/project/deviceManage/getDeviceOnlineStatusAlterLogPage",method = RequestMethod.POST)
    public Page getDeviceOnlineStatusAlterLogPage(@RequestParam("deviceUnique")String deviceUnique, @RequestParam("pageSize")int pageSize, @RequestParam("currentPage")int currentPage) {
        return iOperateDeviceManageService.getDeviceOnlineStatusAlterLogPage(deviceUnique, pageSize, currentPage);
    }

    /**
     * <desc>
     * 保存操作日志信息
     * </desc>
     *
     * @param operationSpecialLog
     * @return
     * @author caoshuai
     * @createDate 2020/12/14 11:30
     */
    @Override
    @RequestMapping(path ="/operate/project/deviceManage/saveOperationSpecialLog",method = RequestMethod.POST)
    public Integer saveOperationSpecialLog(@RequestBody OperationSpecialLogPO operationSpecialLog) throws Exception {
        return iOperateDeviceManageService.saveOperationSpecialLog(operationSpecialLog);
    }

    /**
     * <desc>
     * 获取用户信息
     * </desc>
     *
     * @param myUserName@return
     * @author caoshuai
     * @createDate 2020/12/14 11:30
     */
    @Override
    @RequestMapping(path ="/operate/project/deviceManage/getOperateUserPO",method = RequestMethod.POST)
    public OperateUserInfoPO getOperateUserPO(@RequestParam("myUserName") String myUserName) {

        return iOperateDeviceManageService.getOperateUserPO(myUserName);
    }

    /**
     * <desc>
     *      获取设备的开门方式占比
     * </desc>
     *
     * @param deviceUnique 设备唯一码
     * @return
     * @Author Zhu.yj
     * @createDate  2020/12/23
     */
    @Override
    @PostMapping("/operate/project/deviceManage/getOpenPercent")
    public List<OperatePassPercentVO> getOpenPercent(@RequestParam("deviceUnique") String deviceUnique) throws Exception {
        return iOperateDeviceManageService.getOpenPercent(deviceUnique);
    }


    /**
     * <desc>
     * 查询云设备的推送指令
     * </desc>
     *
     * @param params
     * @Author chengshican
     * @Date 2020-12-29 13:51
     * @Param tableName 数据库表名 ， sn 设备sn ， deviceUnique 设备唯一标识
     * @Return commandStatus 命令处理状态,  updateTime 更新时间,  createTime 创建时间
     * @Exception
     */
    @Override
    @PostMapping("/operate/project/deviceManage/getPushCloudChangeLog")
    public Map<String, Object> getPushCloudChangeLog(Map<String, Object> params) {
        return iOperateDeviceManageService.getPushCloudChangeLog(params);
    }
    /**
     * <desc>
     *      定时获取设备日志
     * </desc>
     *
     *
     * @author maju
     * @createDate 2021/4/27
     */
    @Override
    @PostMapping("/operate/project/deviceManage/getDeviceLogByTask")
    public void getDeviceLogByTask() {
        iOperateDeviceManageService.getDeviceLogByTask();
    }

    /**
     * <desc>
     *      定时下载设备日志
     * </desc>
     *
     *
     * @author maju
     * @createDate 2021/4/27
     */
    @Override
    @PostMapping("/operate/project/deviceManage/downloadDeviceLogByTask")
    public void downloadDeviceLogByTask() {
        iOperateDeviceManageService.downloadDeviceLogByTask();
    }
}
